package com.pojo;

import java.util.Arrays;

public class Sort {
    public static void main(String[] args) {
        int arr[] = {1,2,5,4,2,1,3,7,8,5,45,2,5,4,599};
        //冒泡排序
        for (int i=0; i<arr.length-1; i++){
            for (int j=0; j<arr.length-i-1; j++){
                if (arr[j] < arr[j+1]){
                    g(arr,j,j+1);
                }
            }
        }
//        for (int h:arr){
//            System.out.println(h);
//        }
        System.out.println(Arrays.toString(arr));
        select(arr);
        System.out.println(Arrays.toString(arr));
        insert(arr);
        System.out.println(Arrays.toString(arr));

        int [] sum={1,2,3,4,5,6,7,8,9};
        for (int i=sum.length; i>0; i--){
            int a[] = {i};
                System.out.println(Arrays.toString(a));
        }
    }
    //选择排序
    public static void select(int [] arr){
        for (int i=0; i<arr.length; i++){
            int k = i;
            for (int j = i+1; j<arr.length; j++){
                if (arr[j] > arr[k]){
                    g(arr,k,j);
                }
            }
        }
    }

    //插入排序
    public static void insert(int [] arr){
        for (int i=1; i<arr.length; i++){
            for (int j=i; j>0; j--){
                if (arr[j] > arr[j-1]){
                    g(arr,j,j-1);
                }
            }
        }
    }

    public static void g(int[] arr,int i, int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

}
